﻿using System;
using System.Net;
using SharpGIS;
using Sinergija13.DataModel.Dto.Conf;
using Microsoft.Phone.Reactive;

namespace Sinergija13.DataServices.Web.Conf
{
    public class ConfDataService : IConfDataService
    {
        private string serviceUriString = "https://www.mssinergija.net:5567/Agenda.ashx";
        private const string agendaParameter = "?op=Agenda";
        private const string versionParameter = "?op=Version";

        public IObservable<ConfDataModelDto> GetConfData()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequestCreator.GZip.Create(new Uri(serviceUriString + agendaParameter));
            request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip";
            return request.GetJson<ConfDataModelDto>();
        }

        public IObservable<int> GetVersion()
        {
 	        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(serviceUriString + versionParameter));
            return request.GetText().Select(text => Int32.Parse(text));
        }
    }
}
